import pandas as pd
from itertools import product
from allpairspy import AllPairs   #适用于混合水平参数，自动优化组合数量

##################################
# 正交表生成测试用例(生成全组合,例如下面的例子就有4096条（4的6次方）)
##################################
# 参数水平定义
params = {
    "payType": ["不填", "现金", "POS2", "线上"],
    "dateType": ["下单时间", "订单完成时间", "结算时间", "结算时间"],
    "orderStatus":["不填","单个","多个","多个"],
     "endDate":["有值","无值","有值","无值"],
     "token":["有值","无值","有值","有值"], 
     "orderTransactionType":["不填","未完成","已完成","已完成"],            
    # ... 其他参数定义
}
def all_case(params):

    # 生成全组合（仅演示，实际用正交表筛选）
    all_cases = pd.DataFrame(list(product(*params.values())), columns=params.keys())

    # print(all_cases.head())        # 查看前5行
    for i in all_cases.columns:
        print(i,end="  ")
    for i in all_cases.iterrows():
        print(i)

#注意这里使用params是嵌套列表
params2 = [
    ["不填", "现金", "POS2", "线上"],
    ["下单时间", "订单完成时间", "结算时间", "结算时间"],
    ["不填","单个","多个","多个"],
    ["有值","无值","有值","无值"],
    ["有值","无值","有值","有值"], 
    ["不填","未完成","已完成","已完成"]            
    # ... 其他参数定义
]
def zhengjiao(params):
    # 生成正交组合（非全组合）
    for i, pair in enumerate(AllPairs(params)):
        print(f"用例{i+1}: {pair}")

zhengjiao(params2)